const http = require("http");
const fs = require("fs");
const url = require("url");
const server = http.createServer((req, res) => {
    console.log(req.url);
    var urlRes = url.parse(req.url,true);
    console.log(urlRes);
    let pathname = urlRes.pathname;
    console.log(`姓名是${urlRes.query.name}年龄是${urlRes.query.age}`);
    // /index  和  /index?name=zhangsan
    res.setHeader("Content-Type", "text/html;charest=utf-8");
    if (pathname == "/index") {
        let data = fs.readFileSync("./views/index.html");
        res.write(data);
        res.end();
    }else if(pathname == "/product"){
        let data = fs.readFileSync("./views/product.html");
        res.write(data);
        res.end();
    }else{
        // 第三方资源
    }

})
server.listen(8989);